package org.bing.engine.controller.service;

import java.util.HashMap;
import java.util.Map;

import org.bing.engine.common.logging.Log;
import org.bing.engine.common.logging.LogFactory;
import org.bing.engine.controller.lifecycle.GeneralContainerLifecycle;

public class ContainerRegistry {
    private static final Log logger = LogFactory.getLog(ContainerRegistry.class);
    private Map<String, GeneralContainerLifecycle> managedContainer = new HashMap<String, GeneralContainerLifecycle>();

    public void reg(String name, GeneralContainerLifecycle container) {
        if (managedContainer.containsKey(name)) {
            logger.warn("Container " + name + " is exists, can't regist. ");
        } else {
            managedContainer.put(name, container);
            logger.info("Add container " + name + " to registry. ");
        }
    }

    public GeneralContainerLifecycle get(String name) {
        GeneralContainerLifecycle container = managedContainer.get(name);
        if (container == null) {
            logger.warn("Can't find container by " + name);
        }
        return container;
    }
}
